package com.wdcg.utils;

import com.wdcg.activity.MainActivity;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;

public class NotificationUtils {

	public static void createNotification(Context context, String title, String description, int smallIcon){
		
		NotificationCompat.Builder notification = new NotificationCompat.Builder(context).setContentTitle(title)
				.setContentText(description)
				.setSmallIcon(smallIcon);
				
		Intent resultIntent = new Intent(context, MainActivity.class); 
		
		TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
	    stackBuilder.addParentStack(MainActivity.class); 
	    stackBuilder.addNextIntent(resultIntent); 
	    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
	    notification.setContentIntent(resultPendingIntent);
	    notification.setSound(getAlarmUri());
	    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
	    mNotificationManager.notify(0, notification.build());

	   
	}
	
	private static Uri getAlarmUri() {
	    Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // Originally notification and alarm were switched, but my alarm gets annoying very fast. =b
	    if (alert == null) {
	        alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
	        if (alert == null) {
	            alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
	        }
	    } 
	    return alert;
	}
}
